package com.javasm.transfer;

import com.javasm.domin.entity.SaleOutDepot;
import com.javasm.domin.entity.SodSn;
import com.javasm.domin.vo.SaleOutDepotVo;
import com.javasm.domin.vo.SodSnVo;
import com.javasm.transfer.base.BaseTransfer;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author：马明通
 * @Version：1.0
 * @Date：2022/1/18-15:16
 * @Since:jdk1.8
 * @Description:
 */
@Component
@RequiredArgsConstructor
public class SodSnTransfer extends BaseTransfer<SodSn, SodSnVo> {

    public List<SodSnVo> setSodSn(List<SodSn> sodSns) {
        ArrayList<SodSnVo> sodSnVos = new ArrayList<>();

        int lastId = 0;
        for (int i = 0; i < sodSns.size(); i++) {
            SodSn sodSn = sodSns.get(i);

            if (sodSn.getGdId() != lastId){
                SodSnVo sodSnVo = new SodSnVo();

                List<Integer> gdSnList = new ArrayList<>();
                gdSnList.add(sodSn.getGdSn());

                sodSnVo.setGdId(sodSn.getGdId());
                sodSnVo.setGdSnList(gdSnList);
                sodSnVo.setGfSn(sodSn.getGfSn());
                sodSnVos.add(sodSnVo);
            }else {
                sodSnVos.get(sodSnVos.size()-1).getGdSnList().add(sodSn.getGdSn());
            }
            lastId = sodSn.getGdId();
        }
        return sodSnVos;
    }
}
